<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="keywords" content="">
		<meta name="description" content="">
		<link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
		<link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
		<title>区块链推广管理中心</title>
	</head>
	<style>
		body{
			background: #ffffff;
		}
		.main{
			width: 80%;
			margin: 0 auto;
		}
		.main>.title{
			text-align: center;
			margin-top: 5%;
		}
		#template{
			display: none;
		}
		.block {
			font-size: 25px;
			line-height: 60px;
			height: 60px;
		}
		
		.block:hover {
			background: #f5f5f5;
		}
		
		.block>.ctrl {
			text-align: right;
			display: inline-block;
			float: right;
			height: 100%;
		}
		
		.block .weui_switch {
			vertical-align: middle;
		}
	</style>

	<body>
		<div class='main' style="position: relative;">
			<a href="/telegram.html" style="position: absolute; top: -10px;"><img src="http://cmanage.shinechain.io/imgs/return.jpg" height="48" width="48" style="vertical-align:middle;" /></a>
			<h2 class='title'>关键词自动回复</h2>
			<img src="http://cmanage.shinechain.io/imgs/excelUpload.jpg" height="100" width="400" align="right"/>
	<p style="font-size:large;color: #888888;margin-left: 20px;">&thinsp; &thinsp; &thinsp; &thinsp; &thinsp; 上传如右图格式的excel文件即可输入关键字</p>
	<div style="position: relative;left: 50px;top:50px;">
	<form enctype="multipart/form-data" method="post">
    <input type="file" name="file" id='myfile'/>
    <input type="button" value="上传" id="btn"/>
</form>
<table id="table" border="1" cellspacing="0" cellpadding="0" align="middle" style="font-size: large;">
	<tbody>
	   <tr>
	        <th>关键字</th>
	        <th>回复</th>
	        
	    </tr>
    </tbody>
</table>
</div>

</div>
<!--<div class="weui-cells" id="cells">
  <div class="weui-cell" id='template'>
    <div class="weui-cell__bd">
      <p>{{keyword}}</p>
    </div>
    <div class="weui-cell__ft">{{response}}</div>
    </div>
  
</div>-->




		<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
$(function(){
	var ip = 'http://bot.shinechain.io';
	var getInfo = function () {
	$.get(ip + '/botApi/getAll', function(res) {
	var table=document.getElementById("table");
	var data = res.workBotChatList;
    for(var i=0;i<data.length;i++){
        var row=table.insertRow(table.rows.length);
        var c1=row.insertCell(0);
        c1.innerHTML=data[i].keyword;
        var c2=row.insertCell(1);
        c2.innerHTML=data[i].response;
      
       }
		})
	}
	getInfo();
	$("#btn").click(function(){
            var formData = new FormData();
            formData.append("file" , $("#myfile")[0].files[0]);
            $.ajax({
                type: "POST", // 数据提交类型
                url: ip+"/botApi/chat", // 发送地址
                data: formData, //发送数据
                async: true, // 是否异步
                processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                contentType: false, //
                success: function (data) {
   				if (data.status == 200) {
    				var table=document.getElementById("table");
    				
    				for(var j=table.rows.length-1;j>0;j--){
    					table.deleteRow(j);
    				}
					var data = data.workBotChatList;
    				for(var i=0;i<data.length;i++){
        				var row=table.insertRow(table.rows.length);
       					var c1=row.insertCell(0);
       					c1.innerHTML=data[i].keyword;
        				var c2=row.insertCell(1);
        				c2.innerHTML=data[i].response;
       				}	
   				}
   				else {
    				alert("保存失败：" + data);
   					}
            },
            	error: function(data){
            		alert(data.errorMsg);
            	}
        });
	});
})
</script>
</body>
</html>